package com.klw.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.klw.common.annotation.Log;
import com.klw.common.core.controller.BaseController;
import com.klw.common.core.domain.AjaxResult;
import com.klw.common.enums.BusinessType;
import com.klw.business.domain.KlwWarningResults;
import com.klw.business.service.IKlwWarningResultsService;
import com.klw.common.utils.poi.ExcelUtil;
import com.klw.common.core.page.TableDataInfo;

/**
 * 预警结果Controller
 * 
 * @author klw
 * @date 2025-08-24
 */
@RestController
@RequestMapping("/core/results")
public class KlwWarningResultsController extends BaseController
{
    @Autowired
    private IKlwWarningResultsService klwWarningResultsService;

    /**
     * 查询预警结果列表
     */
    @PreAuthorize("@ss.hasPermi('core:results:list')")
    @GetMapping("/list")
    public TableDataInfo list(KlwWarningResults klwWarningResults)
    {
        startPage();
        List<KlwWarningResults> list = klwWarningResultsService.selectKlwWarningResultsList(klwWarningResults);
        return getDataTable(list);
    }

    /**
     * 导出预警结果列表
     */
    @PreAuthorize("@ss.hasPermi('core:results:export')")
    @Log(title = "预警结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KlwWarningResults klwWarningResults)
    {
        List<KlwWarningResults> list = klwWarningResultsService.selectKlwWarningResultsList(klwWarningResults);
        ExcelUtil<KlwWarningResults> util = new ExcelUtil<KlwWarningResults>(KlwWarningResults.class);
        util.exportExcel(response, list, "预警结果数据");
    }

    /**
     * 获取预警结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('core:results:query')")
    @GetMapping(value = "/{warningId}")
    public AjaxResult getInfo(@PathVariable("warningId") Long warningId)
    {
        return success(klwWarningResultsService.selectKlwWarningResultsByWarningId(warningId));
    }

    /**
     * 新增预警结果
     */
    @PreAuthorize("@ss.hasPermi('core:results:add')")
    @Log(title = "预警结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KlwWarningResults klwWarningResults)
    {
        return toAjax(klwWarningResultsService.insertKlwWarningResults(klwWarningResults));
    }

    /**
     * 修改预警结果
     */
    @PreAuthorize("@ss.hasPermi('core:results:edit')")
    @Log(title = "预警结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KlwWarningResults klwWarningResults)
    {
        return toAjax(klwWarningResultsService.updateKlwWarningResults(klwWarningResults));
    }

    /**
     * 删除预警结果
     */
    @PreAuthorize("@ss.hasPermi('core:results:remove')")
    @Log(title = "预警结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warningIds}")
    public AjaxResult remove(@PathVariable Long[] warningIds)
    {
        return toAjax(klwWarningResultsService.deleteKlwWarningResultsByWarningIds(warningIds));
    }
}
